<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>鑫立方管理系统</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/common.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/main.css" />
<script type="text/javascript" src="<%=basePath%>js/libs/modernizr.min.js"></script>


<script src="<%=basePath%>js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
	
	 $(function(){
		$("#catalogSelect").change(function() {
			var cid = $("#catalogSelect option:selected").val();
			$.get(
				"/factory/getSelectList",
				{c_id: cid},
				function(data) {
					// 清空厂商列表
					var factorySelect = $("#factorySelect");
					factorySelect.empty();
					// 添加符合条件的厂家列表
					if(data.length > 0) {
    					$.each(data, function(index, factory) {
    						factorySelect.append("<option value='" + factory.f_id + "'>" + factory.name + "</option>");
    					});
					} else {
						factorySelect.append("<option>无有效供应商</option>");
					}
				});
		});

	})
</script>
</head>
<body>
  <div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
      <div class="topbar-logo-wrap clearfix">
        <ul class="navbar-list clearfix">
          <li><a class="on" href="#">鑫立方管理系统</a></li>
        </ul>
      </div>
      <div class="top-info-wrap">
        <ul class="top-info-list clearfix">
          <li><a href="/user/logout">退出</a>
        </ul>
      </div>
    </div>
  </div>
  <div class="container clearfix">
    <div class="sidebar-wrap">
      <div class="sidebar-content">
        <ul class="sidebar-list">
          <li><a href="#"><i class="icon-font">&#xe003;</i>主材部</a>
            <ul class="sub-menu">
              <li><a href="<%=basePath + "product/index"%>"><i class="icon-font">&#xe008;</i>商品管理</a>
              </li>
              <li><a href="<%=basePath + "factory/product"%>"><i class="icon-font">&#xe006;</i>厂家管理</a></li>
              <li><a href="<%=basePath + "order/index"%>"><i class="icon-font">&#xe005;</i>订单管理</a>
              </li>
              <c:if test="${sessionScope.xlf_userType == '10' }">
                <li><a href="<%=basePath + "user/index"%>"><i class="icon-font">&#xe009;</i>管理员管理</a>
              </li>
              </c:if>
              <li><a href="<%=basePath + "product/mail"%>"><i class="icon-font">&#xe004;</i>邮件配置</a>
              </li>
              <li><a href="<%=basePath + "email/index"%>"><i class="icon-font">&#xe012;</i>邮件记录</a>
              </li>
            </ul>
          </li>

        </ul>
      </div>
    </div>
    <!--/sidebar-->
    <div class="main-wrap">

      <div class="crumb-wrap">
        <div class="crumb-list">
          <i class="icon-font"></i><a href="index">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">商品管理</span>
        </div>
      </div>
     
      <div class="result-wrap">
        <form action="save" method="post" enctype="multipart/form-data">
          <input type="hidden" name="product.p_id" value="${product.p_id }" />
          <table class="insert-tab" width="100%">
            <tbody>
              <tr>
                <th><i class="require-red">*</i>主材分类：</th>
                <td>
                  <select name="product.c_id" id="catalogSelect">
                    <c:forEach items="${catalogList }" var="catalog" varStatus="s">
                      <c:if test="${product.c_id == catalog.id || catalogId == catalog.id }">
                        <option value="${catalog.id }" selected="selected">${catalog.name }</option>
                      </c:if>
                      <c:if test="${product.c_id != catalog.id}">
                        <option value="${catalog.id }">${catalog.name }</option>
                      </c:if>
                    </c:forEach>
                  </select>
                </td>
              </tr>
              <tr>
                <th><i class="require-red">*</i>供货厂家：</th>
                <td>
                  <select name="product.f_id" id="factorySelect">
                    <c:forEach items="${factoryList }" var="factory" varStatus="s">
                      <c:if test="${product.f_id == factory.f_id || factoryId == factory.f_id }">
                        <option value="${factory.f_id }" selected="selected">${factory.name }</option>
                      </c:if>
                      <c:if test="${product.f_id != factory.f_id}">
                        <option value="${factory.f_id }">${factory.name }</option>
                      </c:if>
                    </c:forEach>
                  </select>
                </td>
              </tr>
              <c:if test="${catalogId == 9 }">
                <!-- 小件默认属于最低档套餐 -->
                <input type="hidden" name="product.planType" value="1">
              </c:if>
              <c:if test="${catalogId != 9 }">
                <tr>
                  <th><i class="require-red">*</i>套餐：</th>
                  <td>
                    <select name="product.planType" id="planType">
                     <c:forEach items="${planList }" var="plan" varStatus="s">
                        <c:if test="${product.planType == plan.id || planId == plan.id }">
                          <option value="${plan.id }" selected="selected">${plan.name }</option>
                        </c:if>
                        <c:if test="${product.planType != plan.id}">
                          <option value="${plan.id }">${plan.name }</option>
                        </c:if>
                     </c:forEach>
                
                    </select>
                  </td>
                </tr>
              </c:if>
              <tr>
                <th><i class="require-red">*</i>
                  <c:if test="${catalogId == 9 }">名称：</c:if>
                  <c:if test="${catalogId != 9 }">品牌：</c:if>
                </th>
                <td><input class="common-text required" name="product.brand" value="${product.brand}" size="50" type="text"></td>
              </tr>
              <c:if test="${catalogId == 9 }">
                <!-- 小件默认有货 -->
                <input type="hidden" name="product.status" value="1"/>
              </c:if>
              <c:if test="${catalogId != 9 }">
                <tr>
                  <th><i class="require-red">*</i>图片：</th>
                  <td><input type="file" size="50" name="img"></td>
                </tr>
                <tr>
                  <th><i class="require-red">*</i>状态：</th>
                  <td><select name="product.status">
                      <c:if test="${product.status == 0 }">
                        <option value="0" selected="selected">无货</option>
                        <option value="1">有货</option>
                      </c:if>
                      <c:if test="${empty product.status || product.status == 1 }">
                        <option value="0">无货</option>
                        <option value="1" selected="selected">有货</option>
                      </c:if>
                  </select>
                  </td>
                </tr>
                <tr>
                  <th><i class="require-red">*</i>型号：</th>
                  <td><input class="common-text required" name="product.type" value="${product.type}" size="50" type="text">
                  </td>
                </tr>
                <tr>
                  <th><i class="require-red">*</i>规格：</th>
                  <td><input class="common-text required" name="product.spec" value="${product.spec}" size="50" type="text">
                  </td>
                </tr>
                <tr>
                  <th><i class="require-red">*</i>材质：</th>
                  <td><input class="common-text required" name="product.material" value="${product.material}" size="50" type="text">
                  </td>
                </tr>
              </c:if>
              <tr>
                <th><i class="require-red">*</i>单位：</th>
                <td><input class="common-text required" name="product.unit" value="${product.unit}" size="50" type="text">
                </td>
              </tr>
              <tr>
                <th><i class="require-red">*</i>自选价格：</th>
                <td><input class="common-text required" name="product.price" value="${product.price}" size="50" type="text">
                </td>
              </tr>
              <c:if test="${sessionScope.xlf_userType == '10' }">
              <tr>
                <th><i class="require-red">*</i>供货价格：</th>
                <td><input class="common-text required" name="product.innerPrice" value="${product.innerPrice}" size="50" type="text">
                </td>
              </tr>
              </c:if>
              <tr>
                <th><i class="require-red">*</i>备注：</th>
                <td><input class="common-text required" name="product.productRemark" value="${product.productRemark}" size="50" type="text">
                </td>
              </tr>
              <c:if test="${catalogId != 9 }">
                <tr>
                  <th><i></i>孔距：</th>
                  <td><input class="common-text required" name="product.hole" value="${product.hole}" size="50" type="text">（卫浴专用）</td>
                </tr>
                <tr>
                  <th><i></i>颜色：</th>
                  <td><input class="common-text required" name="product.color" value="${product.color}" size="50" type="text">（木门专用）</td>
                </tr>
                <tr>
                  <th><i></i>玻璃型号：</th>
                  <td><input class="common-text required" name="product.glassType" value="${product.glassType}" size="50" type="text">（拉门专用）</td>
                </tr>
                <tr>
                  <th><i></i>型材型号：</th>
                  <td><input class="common-text required" name="product.materialType" value="${product.materialType}" size="50" type="text">（拉门专用）</td>
                </tr>
                <tr>
                  <th><i></i>材料名称：</th>
                  <td><input class="common-text required" name="product.materialName" value="${product.materialName}" size="50" type="text">（瓷砖专用）</td>
                </tr>
              </c:if>
              <tr>
                <th></th>
                <td><input class="btn btn-primary btn6 mr10" value="提交" type="submit"> <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button"></td>
              </tr>
            </tbody>
          </table>
        </form>
      </div>
    </div>
    <!--/main-->
  </div>

</body>
</html>